<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<jsp:include page="../inc.jsp"></jsp:include>

<script type="text/javascript" src="../My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="../jslib/date.js"></script>
<script type="text/javascript" charset="utf-8">
	$(function() {
	    $('#d4311').val((new Date()).pattern("yyyy-MM-01"));
	    $('#d4312').val((new Date()).pattern("yyyy-MM-dd"));
		var datagrid = $('#datagrid').datagrid({
			url : 'salelistAction!datagridTotal.html',
			title : '营业员销售列表',
			iconCls : 'icon-save',
			pagination : true,
			pagePosition : 'bottom',
			pageSize : 5,
			pageList : [ 5, 10 ],
			fit : true,
			fitColumns : false,
			nowrap : false,
			border : false,
			idField : 'id',
			checkOnSelect : false,
			selectOnCheck : true,
			/* columns : [ [  {
				title : '营业员',
				field : 'uusername',
				width : 150,
				align:'center'
			},  {
				title : '销售总额',
				field : 'total',
				width : 150,
				align:'center'
			}, {
				title : '销售成本',
				field : 'buyprice',
				width : 150,
				align:'center'
			}, {
				title : '销售利润',
				field : 'total',
				width : 150,
				align:'center'
			} ] ],	 */		
			onRowContextMenu : function(e, rowIndex, rowData) {
				e.preventDefault();
				$(this).datagrid('unselectAll');
				$(this).datagrid('selectRow', rowIndex);
				$('#menu').menu('show', {
					left : e.pageX,
					top : e.pageY
				});
			}
		});
		fetchData("user");
		$('#datagrid').datagrid('reload');
		
		var rid = $('#searchForm').find('input[name=rid]');
		var ridCombobox = rid.combobox({
			url : '${pageContext.request.contextPath}/rkgl/repertoryAction!noAuth_combobox.html',
			valueField : 'id',
			textField : 'name',
			multiple : false,
			editable : false,
			panelHeight : 'auto'
		});

	});
	
	//拼装datagrid
	function fetchData(groupby) { 
		var ss = "[[{title : '营业员',field : 'uusername',width : 150,align:'center'},";
		if(groupby=="repertory"){
			ss = "[[{title : '仓库',field : 'rname',width : 150,align:'center'},";
		}else if(groupby=="brand"){		
			ss = "[[{title : '品牌',field : 'bname',width : 150,align:'center'},";
		}
	    var s = ss+
	    	"{title : '销售总额',field : 'total',width : 150,align:'center'},"+
	    	"{title : '销售成本',field : 'buyprice',width : 150,align:'center'},"+
	    	"{title : '销售利润',field : 'profit',width : 150,align:'center'}]]"
	    options={}; 
	    options.columns = eval(s);
	  	$('#datagrid').datagrid(options);
	} 
	
	function _search() {

		var groupby = $('#searchForm input[name="groupby"]:checked').val();
		fetchData(groupby);
		//datagrid.datagrid('load', {});
		$('#datagrid').datagrid('load', sy.serializeObject($('#searchForm')));

		//传入时间
		var beginDate=$("#d4311").val();
		var endDate=$("#d4312").val();
		//beginDate
		//endDate
		
		var params="";
		if(beginDate!=null&&endDate!=null){
			params+="&beginDate="+beginDate+"&endDate="+endDate+"";
		}
		
		$("#totalimgtotal").attr("src","${pageContext.request.contextPath}/xsgl/salelistAction!saleTotalChart.html?order=total&groupby="+groupby+params+"&random="+Math.random());
		$("#totalimgbuyPrice").attr("src","${pageContext.request.contextPath}/xsgl/salelistAction!saleTotalChart.html?order=buyPrice&groupby="+groupby+params+"&random="+Math.random());
		$("#totalimgprofit").attr("src","${pageContext.request.contextPath}/xsgl/salelistAction!saleTotalChart.html?order=profit&groupby="+groupby+params+"&random="+Math.random());
	}
	
	function cleanSearch() {	    
		datagrid.datagrid('load', {});
		$('#searchForm input').val('');
	}
</script>

</head>
<body class="easyui-layout" data-options="fit:true">
	<div data-options="region:'north',border:false,title:'过滤条件'" style="height: 55px;overflow: hidden;" align="left">
		<form id="searchForm">
			<table class="tableForm datagrid-toolbar" style="width: 100%;height: 100%;">
				<tr>
					<!--  <th style="width:60px;">营业员</th>
					<td style="width:16px;"><input name=uusername style="width:110px;" /></td> -->
					<th style="width:60px;">所属仓库</th>
					<td style="width:16px;"><input name="rid" style="width: 110px;" /></td>
					<th style="width:60px;">开始时间</th>
					<td style="width:16px;"> 					  
					<input id="d4311" name="beginDate" class="easyui-validatebox" data-options="required:'true',missingMessage:'请选择销售时间'" style="width: 110px;" onClick="WdatePicker()" onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'d4312\')||\'2030-10-01\'}'})"/></td>
					<th style="width:60px;">结束时间</th>
					<td style="width:16px;">					 
					<input id="d4312" name="endDate"   class="easyui-validatebox" data-options="required:'true',missingMessage:'请选择销售时间'" style="width: 110px;" onClick="WdatePicker()" onFocus="WdatePicker({minDate:'#F{$dp.$D(\'d4311\')}',maxDate:'2030-10-01'})"/></td>
					<td>统计方式
					<input type="radio" name="groupby" id="groupby" value="user" checked="checked" style="width: 10px;"/>按营业员
					<input type="radio" id="groupby" name="groupby" value="repertory" style="width: 10px;"/>按仓库
					<input type="radio" id="groupby" name="groupby" value="brand" style="width: 10px;"/>按品牌</td>
					<td><a href="javascript:void(0);" class="easyui-linkbutton" onclick="_search();">查询</a><a href="javascript:void(0);" class="easyui-linkbutton" onclick="cleanSearch();">清空</a></td>
				</tr>
			</table>
		</form>
	</div>
	<div data-options="region:'center',border:false" style="height: 55px;overflow: hidden;">
		<table id="datagrid"></table>
	</div>
	<div id="chartimgs" data-options="region:'south',border:false" style="height: 240px;width:945;overflow-x:auto; overflow-y:hidden;">
		<div style="width:945px;overflow-x:auto; overflow-y:hidden;">
			<img id="totalimgtotal" align="left" src="${pageContext.request.contextPath}/xsgl/salelistAction!saleTotalChart.html?order=total"/>
			<img id="totalimgbuyPrice" align="center" src="${pageContext.request.contextPath}/xsgl/salelistAction!saleTotalChart.html?order=buyPrice"/>
			<img id="totalimgprofit" align="right" src="${pageContext.request.contextPath}/xsgl/salelistAction!saleTotalChart.html?order=profit"/>
		</div>
	</div>
</body>

</html>